from django.db import models

class UserGroup(models.Model):
   # creator     = models.ForeignKey(User)
    name        = models.CharField(max_length=50)
    create_time = models.DateTimeField('data utworzenia')

    
class User(models.Model):
    USER_STATUS = (
        (u'N', u'Nowy'),
        (u'A', u'Aktywny'),
        (u'Z', u'Nieaktywny'),
    )
    group           = models.ForeignKey(UserGroup)
    firstname       = models.CharField(max_length=30)
    surname         = models.CharField(max_length=50)
    email           = models.CharField(max_length=50)
    password        = models.CharField(max_length=20)
    status          = models.CharField(max_length=2, choices=USER_STATUS)
    register_time   = models.DateTimeField('data rejestracji')
    last_visit_time = models.DateTimeField('czas ostatniej wizyty')

 
class Category(models.Model):
    CATEGORY_STATUS = (
        (u'P', u'Proponowana'),
        (u'Z', u'Zaaprobowana'),
        (u'O', u'Odrzucona'),
    )
   # parent      = models.ForeignKey(Category)
    creator     = models.ForeignKey(User)
    name        = models.CharField(max_length=30)
    create_time = models.DateTimeField('data utworzenia')
    status      = models.CharField(max_length=2, choices=CATEGORY_STATUS)

    
class QuestionsSet(models.Model):
    creator     = models.ForeignKey(User)
    name        = models.CharField(max_length=30)
    create_time = models.DateTimeField('data utworzenia')

class Question(models.Model):
#    QUESTION_STATUS = ?? TODO 
    set         = models.ForeignKey(QuestionsSet)
    content     = models.CharField(max_length=255)
    status      = models.CharField(max_length=2)
    
    
class ExamDefinition(models.Model):
    creator      = models.ForeignKey(User)
    name         = models.CharField(max_length=30)
    description  = models.CharField(max_length=510)
    create_time  = models.DateTimeField('czas rozpoczecia')
    
class QuestionDefinition(models.Model):
#    QDEF_TYPE = ?? TODO 
    exam_def      = models.ForeignKey(ExamDefinition)
    question      = models.ForeignKey(Question)
    set           = models.ForeignKey(QuestionsSet)
    category      = models.ForeignKey(Category)
    content       = models.CharField(max_length=255)
    type          = models.CharField(max_length=2)
    points_amount = models.IntegerField()

class QuestionResponse(models.Model):
    RESPONSE_CORRECT = (
        (u'T', u'Tak'),
        (u'N', u'Nie'),
    )
    question    = models.ForeignKey(Question)
    content     = models.CharField(max_length=255)
    correct     = models.CharField(max_length=2, choices=RESPONSE_CORRECT)


class ExamResult(models.Model):
    RESULT_CORRECT = (
        (u'T', u'Tak'),
        (u'N', u'Nie'),
    )
    member        = models.ForeignKey(User)
    exam_def      = models.ForeignKey(ExamDefinition)
    points_amount = models.IntegerField()
    start_time  = models.DateTimeField('czas rozpoczecia')
    finish_time = models.DateTimeField('data ukonczenia')

class QuestionResult(models.Model):
    RESULT_CORRECT = (
        (u'T', u'Tak'),
        (u'N', u'Nie'),
    )
    quest_def   = models.ForeignKey(QuestionDefinition)
    response    = models.ForeignKey(QuestionResponse)
    content     = models.CharField(max_length=255)
    correct     = models.CharField(max_length=2, choices=RESULT_CORRECT)
